package cn.siat.gene.controller;

import cn.siat.common.security.utils.SecurityUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.siat.common.core.web.controller.BaseController;
import cn.siat.common.core.web.domain.AjaxResult;
import cn.siat.gene.domain.MolecularParameter;
import cn.siat.gene.service.MolecularParameterService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/molecular/parameter")
@RequiredArgsConstructor
public class MolecularParameterController extends BaseController {
    private final MolecularParameterService molecularParameterService;

    @PostMapping(value = {"","/"})
    public AjaxResult saveParameter(@RequestBody MolecularParameter molecularParameter){
        molecularParameter.setCreateBy(SecurityUtils.getUserId()).setCreateTime(new Date());
        molecularParameterService.save(molecularParameter);
        return AjaxResult.success("保存成功！");
    }

    @GetMapping(value = {"","/"})
    public AjaxResult getParameter(MolecularParameter molecularParameter){
        QueryWrapper<MolecularParameter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("operate_id", molecularParameter.getOperateId())
                        .eq("mode", molecularParameter.getMode());
        MolecularParameter one = molecularParameterService.getOne(queryWrapper);
        return AjaxResult.success("获取成功!",one);
    }

    @DeleteMapping(value = {"","/"})
    public AjaxResult deleteParameter(@RequestBody MolecularParameter molecularParameter){
        QueryWrapper<MolecularParameter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("operate_id", molecularParameter.getOperateId())
                .eq("mode", molecularParameter.getMode());
        molecularParameterService.remove(queryWrapper);
        return AjaxResult.success("删除成功!");
    }
}
